package com.han.yrpc.registrycenter.localcache;

import com.han.yrpc.core.registry.ServiceInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

@Component
@Slf4j
public class ServiceProvider {

    private final Map<String, Set<ServiceInfo>> serviceHolder = new ConcurrentHashMap<>();

    public void addService(String serviceName, ServiceInfo serviceInfo) {
        Set<ServiceInfo> set = serviceHolder.computeIfAbsent(serviceName, k -> new HashSet<>());
        set.add(serviceInfo);
    }

    public Set<ServiceInfo> getService(String serviceName) {
        return serviceHolder.get(serviceName);
    }

}
